package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.CustUser;
import com.ruoyi.project.system.service.ICustUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 平台账号Controller
 * 
 * @author ruoyi
 * @date 2021-04-26
 */
@RestController
@RequestMapping("/system/custuser")
public class CustUserController extends BaseController
{
    @Autowired
    private ICustUserService custUserService;

    /**
     * 查询平台账号列表
     */
    @PreAuthorize("@ss.hasPermi('system:custuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustUser custUser)
    {
        startPage();
        List<CustUser> list = custUserService.selectCustUserList(custUser);
        return getDataTable(list);
    }

    /**
     * 导出平台账号列表
     */
    @PreAuthorize("@ss.hasPermi('system:custuser:export')")
    @Log(title = "平台账号", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustUser custUser)
    {
        List<CustUser> list = custUserService.selectCustUserList(custUser);
        ExcelUtil<CustUser> util = new ExcelUtil<CustUser>(CustUser.class);
        return util.exportExcel(list, "custuser");
    }

    /**
     * 获取平台账号详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:custuser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(custUserService.selectCustUserById(id));
    }

    /**
     * 新增平台账号
     */
    @PreAuthorize("@ss.hasPermi('system:custuser:add')")
    @Log(title = "平台账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustUser custUser)
    {
        return toAjax(custUserService.insertCustUser(custUser));
    }

    /**
     * 修改平台账号
     */
    @PreAuthorize("@ss.hasPermi('system:custuser:edit')")
    @Log(title = "平台账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustUser custUser)
    {
        return toAjax(custUserService.updateCustUser(custUser));
    }

    /**
     * 删除平台账号
     */
    @PreAuthorize("@ss.hasPermi('system:custuser:remove')")
    @Log(title = "平台账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(custUserService.deleteCustUserByIds(ids));
    }
}
